import scrapy
from scrapy import Request, FormRequest

class LoginSpider(scrapy.Spider):
    name = 'login1'
    allowed_domains = ['17k.com']
    start_urls = ['https://user.17k.com/www/']

    def parse(self, response):
        print(response.text)

    def start_requests(self):
        # 直接从 浏览器复制 cookie
        cookies = "GUID=d69afa45-6723-43a7-9d9c-1845e6df0d4c; c_channel=0; c_csc=web; Hm_lvt_9793f42b498361373512340937deb2a0=1698411700,1698416042,1698416654; accessToken=avatarUrl%3Dhttps%253A%252F%252Fcdn.static.17k.com%252Fuser%252Favatar%252F02%252F82%252F71%252F102357182.jpg-88x88%253Fv%253D1698411887000%26id%3D102357182%26nickname%3DY%25E9%25AA%2581%25E5%258B%2587%25E5%2596%2584%25E6%2588%2598Y%26e%3D1713968655%26s%3Da357e246664654ad; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22102357182%22%2C%22%24device_id%22%3A%2218b717fe9c8101-0cdaf2cd30d718-17525634-1296000-18b717fe9c9fc2%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%2C%22first_id%22%3A%22d69afa45-6723-43a7-9d9c-1845e6df0d4c%22%7D; Hm_lpvt_9793f42b498361373512340937deb2a0=1698416662"

        # 将 cookie 以字典形式存储
        cookie_dic = {}
        for c in cookies.split("; "):
            k, v = c.split("=")
            cookie_dic[k] = v

        # 发送请求
        yield Request(
            url=LoginSpider.start_urls[0],
            cookies=cookie_dic,
            callback=self.parse # 执行回调函数
        )